/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;
import DAL.ConnectUnit;
import DTO.Customer_DTO;
import DTO.SavingType_DTO;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Vector;
public class Customer_BLL {
    public ConnectUnit connection;
    //hàm tạo
    public Customer_BLL() throws ClassNotFoundException
    {
        this.connection = DAL.DAL.getDAL();
    }
    //get all customers
    public Vector<Customer_DTO> GetCustomers(String condition, String OrderBy) throws Exception{
        Vector<Customer_DTO> customers = new Vector<Customer_DTO>();
        ResultSet result = this.connection.Select("customer", condition, OrderBy);
        while(result.next()){
            Customer_DTO customer = new Customer_DTO();
            customer.setCustomerID(result.getString("CustomerID"));
            customer.setFullName(result.getString("FullName"));
            customer.setIDNumber(result.getString("IdNumber"));
            customer.setHomeAddress(result.getString("HomeAddress"));
            customer.setPhone(result.getString("Phone"));
            customer.setEmail(result.getString("Email"));
            customers.add(customer);
        }
        return customers;
    }
    public Vector<Customer_DTO> GetCustomers(String condition) throws Exception{
        return this.GetCustomers(condition, null);
    }
    //select toàn bộ dữ  liệu từ table
    public Vector<Customer_DTO> GetCustomers() throws Exception{
        return this.GetCustomers(null, null);
    }
    //lấy từng dòng dữ liệu từ table
     public Customer_DTO getCustomerByIndex(Vector<Customer_DTO> list, int index){
        return (index >= list.size()) ? null : list.toArray(new Customer_DTO[list.size()])[index];
    }
}
